package www.openteam.com.model.qualityCntrl;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import www.openteam.com.base.BaseModel;
import www.openteam.com.bean.IPQCCheckMan;
import www.openteam.com.bean.IPQCMachine;
import www.openteam.com.bean.IPQCMsg00;
import www.openteam.com.bean.IPQCMsg01;
import www.openteam.com.bean.IPQCProduce;
import www.openteam.com.bean.SendRcvBean;
import www.openteam.com.model.PrdctnMngmnt.SendRcvModel;

/**
 * Created by OT on 2018-01-09.
 */

public class IPQCModel extends BaseModel {


    public void findProduce( final IPQCModel.ProduceListener listener){
        httpApiService.findProMsg().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<IPQCProduce>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e);
                    }

                    @Override
                    public void onNext(IPQCProduce ipqcProduce) {
                        listener.success(ipqcProduce);
                    }
                })
        ;
    }

    public void findProMachine( String code,final IPQCModel.MachineListener listener){
        httpApiService.findMachine(code).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<IPQCMachine>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e);
                    }

                    @Override
                    public void onNext(IPQCMachine ipqcMachine) {
                        listener.success(ipqcMachine);
                    }
                })
        ;
    }

    public void findCheckMan( final IPQCModel.CheckManListener listener){
        httpApiService.findPeople().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<IPQCCheckMan>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e);
                    }

                    @Override
                    public void onNext(IPQCCheckMan ipqcCheckMan) {
                        listener.success(ipqcCheckMan);
                    }
                })
        ;
    }

    public void findMsg00(String producecode, final IPQCModel.Msg00Listener listener){
        httpApiService.findMsg00(producecode).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<IPQCMsg00>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e);
                    }

                    @Override
                    public void onNext(IPQCMsg00 ipqcMsg00) {
                        listener.success(ipqcMsg00);
                    }
                })
        ;
    }

    public void findMsg01( String producecode,final IPQCModel.Msg01Listener listener){
        httpApiService.findMsg01(producecode).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<IPQCMsg01>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e);
                    }

                    @Override
                    public void onNext(IPQCMsg01 ipqcMsg01) {
                        listener.success(ipqcMsg01);
                    }
                })
        ;
    }

    public interface ProduceListener{
        void success(IPQCProduce IPQCProduce);

        void fail(Throwable e);
    }

    public interface MachineListener{
        void success(IPQCMachine IPQCMachine);

        void fail(Throwable e);
    }

    public interface CheckManListener{

        void success(IPQCCheckMan ipqcCheckMan);
        void fail(Throwable e);
    }
    public interface Msg00Listener{
        void success(IPQCMsg00 ipqcMsg00);

        void fail(Throwable e);
    }
    public interface Msg01Listener{
        void success(IPQCMsg01 ipqcMsg01);

        void fail(Throwable e);
    }
}
